<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-11
  Time: 14:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%@ page import="service.BatteryService" %>
<%@ page import="service.impl.BatteryServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Battery" %>
<%@ page import="service.RoomService" %>
<%@ page import="service.impl.RoomServiceImpl" %>
<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-09
  Time: 14:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
    <style>
        table tr td {
            border: 1px solid #ccc;
        }
    </style>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>

</head>
<body>
<table>
    <tr>
        <td>序号</td>
        <td>机房名称</td>
        <td>机房数量</td>
        <td>机房管理员</td>
        <td>机房位置</td>
        <td>机房状态</td>
        <td>操作</td>
    </tr>
    <%
        request.setCharacterEncoding("utf-8");
        RoomService roomService = new RoomServiceImpl();
        List list = roomService.info();
        request.setAttribute("list",list);
    %>
    <c:forEach items="${list}" var="room">
        <tr>
            <td>${room.roomId}</td>
            <td>${room.roomName}</td>
            <td>${room.computerNumber}</td>
            <td>${room.manager}</td>
            <td>${room.location}</td>
            <c:if test="${room.state==1}">
                <td>使用</td>
            </c:if>
            <c:if test="${room.state==2}">
                <td>空闲</td>
            </c:if>
            <c:if test="${room.state==3}">
                <td>维护</td>
            </c:if>
            <td><a href="#" onclick="Delete(${room.roomId})">删除</a>
                <a href="./room_Inset.jsp">新增</a></td>
        </tr>
    </c:forEach>
</table>
<script>
    function Delete(id) {
        var sf =confirm("确定要删除吗？")
        if (sf == true){
            $.get("<%=request.getContextPath()%>/RoomDeleteServlet","id="+id,function (data){
                if (data >0){
                    alert("删除成功!")
                    return true
                    location.href="room_All.jsp";
                }else {
                    alert("删除失败!")
                }
            })
        }
    }
</script>
</body>
</html>
</body>
</html>
